Passed
Push — master ( 68d566...33bc6b )
by Tom
02:09 queued 11s
created

ErrorBoundary   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 19
dl 0
loc 24
c 0
b 0
f 0
rs 10

3 Functions

Rating   Name   Duplication   Size   Complexity  
A getDerivedStateFromError 0 3 1
A componentDidCatch 0 4 1
A render 0 9 2
1
import React, { Component } from 'react'
2
3
export default class ErrorBoundary extends Component {
4
  constructor(props) {
5
    super(props)
6
    this.state = { hasError: false }
7
  }
8
9
  static getDerivedStateFromError() {
10
    return { hasError: true }
11
  }
12
13
  componentDidCatch(error, errorInfo) {
14
    // eslint-disable-next-line no-console
15
    console.log(error, errorInfo)
16
  }
17
18
  render() {
19
    // eslint-disable-next-line react/destructuring-assignment
20
    if (this.state.hasError) {
21
      return <h1>Something went wrong.</h1>
22
    }
23
24
    // eslint-disable-next-line react/destructuring-assignment, react/prop-types
25
    return this.props.children
26
  }
27
}
28